package com.shiguiwu.springmybatis.spring.lifecycle.setprop;

import com.shiguiwu.springmybatis.spring.lifecycle.definition.Pig;
import org.springframework.beans.PropertyValues;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.beans.factory.config.InstantiationAwareBeanPostProcessor;
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;

import java.util.Arrays;

/**
 * @description: 8.1实例化后阶段
 * @author: stone
 * @date: Created by 2021/3/25 20:14
 * @version: 1.0.0
 * @pakeage: com.shiguiwu.springmybatis.spring.lifecycle.setprop
 */
public class InstancedTests {

    public static void main(String[] args) {
        DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
        factory.addBeanPostProcessor(new MyInstantiationAwareBeanPostProcessor());

        BeanDefinition beanDefinition = BeanDefinitionBuilder.genericBeanDefinition(Pig.class)
                .addPropertyValue("name", "猪八戒")
                .addPropertyValue("age", 30)
                .getBeanDefinition();

        BeanDefinition beanDefinition1 = BeanDefinitionBuilder.genericBeanDefinition(Pig.class)
                .addPropertyValue("name", "猪悟能")
                .addPropertyValue("age", 35)
                .getBeanDefinition();

        factory.registerBeanDefinition("pig", beanDefinition);
        factory.registerBeanDefinition("pig1", beanDefinition1);

        Arrays.stream(factory.getBeanDefinitionNames()).forEach(s -> System.out.println(factory.getBean(s)));



    }
}
